﻿@page "/Account/Login"

@using Microsoft.AspNetCore.Authentication
@using System.Security.Claims
@using Microsoft.AspNetCore.Authentication.Cookies
@inject NavigationManager NavigationManager

<h3>Login</h3>

<form method="post" @onsubmit="StartLogin" @formname="lll">
    <AntiforgeryToken />
    <button type="submit">登录</button>
</form>



@code {

    private string? errorMessage;

    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;


    [SupplyParameterFromQuery]
    private string? ReturnUrl { get; set; }

    protected override async Task OnInitializedAsync()
    {
        await Task.Delay(1);
        if (HttpMethods.IsGet(HttpContext.Request.Method))
        {
            await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
        }
    }
    public void L()
    {

    }
    public async Task StartLogin()
    {
        var id = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
        id.AddClaim(new Claim(ClaimTypes.NameIdentifier, "Zmm"));
        id.AddClaim(new Claim(ClaimTypes.Name, "Zmm"));
        id.AddClaim(new Claim("CorpId", "10000"));
        ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(id);
        AuthenticationProperties properties = new AuthenticationProperties { IsPersistent = true };
        await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrincipal, properties);

        NavigationManager.NavigateTo(ReturnUrl ?? "/");
    }

}
